package com.leezt.designpattern.principles.OCP.handlers;

import com.leezt.designpattern.principles.OCP.common.NotificationEmergencyLevel;
import com.leezt.designpattern.principles.OCP.models.ApiStatInfo;
import com.leezt.designpattern.principles.OCP.services.AlertRuleManager;
import com.leezt.designpattern.principles.OCP.services.INotify;

public class TpsAlertHandler extends AlertHandler {
    public TpsAlertHandler(AlertRuleManager ruleMgr, INotify notification) {
        super(ruleMgr, notification);
    }

    @Override
    public void check(ApiStatInfo apiStatInfo) {
        long tps = apiStatInfo.getRequestCount() / apiStatInfo.getDurationOfSeconds();
        if (tps > ruleMgr.getMatchedRule(apiStatInfo.getApi()).getMaxTps()) {
            notification.notify(NotificationEmergencyLevel.URGENCY, "...");
        }
    }
}
